// pages/sousuo/sousuo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShow:true,
    showInputField: true,
    arrList:["心理专家","心理文章","心理测试","提问回答"],
    hasContent: false,
    sousuo:""
  },

  gotoSerach(e){
   const index = e.currentTarget.dataset.index+1;
   console.log(index)
    wx.navigateTo({
      url: '/pages/search/search?index='+index,
    })
  },

  gotoExpert(){
      wx.navigateTo({
        url: '/pages/search/searchExpert/searchExpert',
      })
  },
  gotoArticle(){
      wx.navigateTo({
        url: '/pages/search/searchArticle/searchArticle',
      })
  },
  gotoTest(){
      wx.navigateTo({
        url: '/pages/search/searchTest/searchTest',
      })
  },
  gotoAnswer(){
      wx.navigateTo({
        url: '/pages/search/searchQuestion/searchQuestion',
      })
  },

  showInput() {
    this.setData({ showInputField: true });
    // 延迟设置焦点，以确保输入框显示后键盘弹出
    setTimeout(() => {
      this.setData({ focus: true });
    }, 100);

    let that = this;
    console.log(that.data.hasContent)
    // 长度大于0时跳转页面
    if(that.data.hasContent&&that.data.hasContent!=""){
      wx.navigateTo({
        url: `/pages/search/searchall/searchall?keyword=${this.data.sousuo}`,
      })
    }
    that.setData({
      sousuo:"",
      hasContent: false,
    })
  },
  onInput(event) {
    console.log('输入的内容:', event.detail.value);
    const inputValue = event.detail.value.trim();
    this.setData({
      hasContent: inputValue.length > 0
    });
    
  },
  gotoindex(){
     wx.switchTab({
       url: '/pages/index/index',
     })
  },
  gotoclearhistorypage(){
    this.setData({
      isShow:false,
      sousuo:""
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})